Create a DXL Attribute

Hi,

I'm new to DXL and I have a small question.
It's possible to create a DXL Attribute via a DXL Script?
Like the same way if you use the menue Edit/Attributes..., click new, select DXL attribute, than click the Browse button and so on
Can anyone help?

Thanks
Knut
melman - Tue Aug 30 05:46:19 EDT 2011

Re: Create a DXL Attribute
mcnairk - Tue Aug 30 08:13:45 EDT 2011

Look up "create (attribute definition)" in the DXL Reference Manual. Here's a simple example:
 

create object type "Boolean" (default "False") attribute "MyNewAttr"

 


Hope this helps,
Ken.

 

Re: Create a DXL Attribute
llandale - Tue Aug 30 14:47:20 EDT 2011

mcnairk - Tue Aug 30 08:13:45 EDT 2011

Look up "create (attribute definition)" in the DXL Reference Manual. Here's a simple example:
 

create object type "Boolean" (default "False") attribute "MyNewAttr"

 


Hope this helps,
Ken.

 

string DxlCode = wherever I get the code
string NameAttr = "Whatever"
create(object type "string" dxl DxlCode attribute NameAttr)

Note that the code will generate some kind of data

obj.attrDXLName = Results

and 'Results' will need to match your attr 'type'; most attr DXL will be type 'string'.

  • Louie

Re: Create a DXL Attribute
melman - Fri Sep 02 05:13:53 EDT 2011

Thanks Ken and Louie for your help.
I've now found a solution.
 

string NameAttr = "Whatever"
  Buffer DXLsrc = create
  DXLsrc  =  Line 1
  DXLsrc +=  Line 2
  .
  .
  .
  string DxlCode = stringOf DXLsrc
  delete DXLsrc
  create(object type "string" dxl DxlCode attribute NameAttr)


 


I do not know if this is the perfect way, but it works.

Thanks

 

Re: Create a DXL Attribute
llandale - Fri Sep 02 12:03:22 EDT 2011

melman - Fri Sep 02 05:13:53 EDT 2011

Thanks Ken and Louie for your help.
I've now found a solution.
 

string NameAttr = "Whatever"
  Buffer DXLsrc = create
  DXLsrc  =  Line 1
  DXLsrc +=  Line 2
  .
  .
  .
  string DxlCode = stringOf DXLsrc
  delete DXLsrc
  create(object type "string" dxl DxlCode attribute NameAttr)


 


I do not know if this is the perfect way, but it works.

Thanks

 

Nothing wrong with that, but perhaps these two little technques have some merit:
You wrote this:

string NameAttr = "Whatever"
Buffer DXLsrc = create
DXLsrc  =  "string Text = obj.\"Object Text\""
DXLsrc +=  "if (null Text)//"
DXLsrc +=  "then obj.attrDXLName = \"Text is null\""
DXLsrc +=  "else obj.attrDXLName = \"There is Text\""
 
string DxlCode = stringOf DXLsrc
delete DXLsrc
print "DxlCode [" DxlCode "]\n"
create(object type "string" dxl DxlCode attribute NameAttr)


1 The following may prevent some leakage in memory. The results of tempStringOf(Buffer) must be disposed of immediately such as printing, writing to a file, display in a dialog, assigning to an attr value, or in this case giving to the attr def. If you assign it to a string variable you can (in fact will) get future corruption as the space of the buffer can and will get overwritten, changing the value of the variable. This won't matter in this little code but does matter in your much larger scripts, say retrieving the value of 10,000 Object Text values.

So use tempStringOf(Buffer) when you are finally disposing its contents.

 

...
create(object type "string" dxl (tempStringOf(DXLsrc)) attribute NameAttr)
delete(DXLsrc)


2 There is also this little string technique for writing paragraphs. Note that there is only one set of double-quotes, first and last, the others inside the text are escaped. The natural End-Of-Lines in the editor are interpreted as part of the string:

 

 

string NameAttr = "Whatever"
string DxlCode  =
"string Text = obj.\"Object Text\"
if (null Text)//
then obj.attrDXLName = \"Text is null\"
else obj.attrDXLName = \"There is Text\"
"    // end definition of string DxlCode
 
create(object type "string" dxl DxlCode attribute NameAttr)
print "DxlCode [" DxlCode "]\n"


I find that string paragraph method easier to read than the Buffer append method.
When the DxlCode uses variables, such as passing into it the name of the Attr to check, the extra string concatenation will matter if you build the DxlCode frequently; in which case you could combine both methods:
{code}
string NameAttr = "Rational"
DXLsrc = "string Text = obj."
DxlSrc += NameAttr
DXLsrc += "
if (null Text)//
then obj.attrDXLName = \"Text is null\"
else obj.attrDXLName = \"There is Text\"
"

Which, now that I look at it, isn't very easy to read!

 

 

 

  • Louie

 

 

Re: Create a DXL Attribute
melman - Tue Sep 27 02:44:12 EDT 2011

llandale - Fri Sep 02 12:03:22 EDT 2011

Nothing wrong with that, but perhaps these two little technques have some merit:
You wrote this:

string NameAttr = "Whatever"
Buffer DXLsrc = create
DXLsrc  =  "string Text = obj.\"Object Text\""
DXLsrc +=  "if (null Text)//"
DXLsrc +=  "then obj.attrDXLName = \"Text is null\""
DXLsrc +=  "else obj.attrDXLName = \"There is Text\""
 
string DxlCode = stringOf DXLsrc
delete DXLsrc
print "DxlCode [" DxlCode "]\n"
create(object type "string" dxl DxlCode attribute NameAttr)


1 The following may prevent some leakage in memory. The results of tempStringOf(Buffer) must be disposed of immediately such as printing, writing to a file, display in a dialog, assigning to an attr value, or in this case giving to the attr def. If you assign it to a string variable you can (in fact will) get future corruption as the space of the buffer can and will get overwritten, changing the value of the variable. This won't matter in this little code but does matter in your much larger scripts, say retrieving the value of 10,000 Object Text values.

So use tempStringOf(Buffer) when you are finally disposing its contents.

 

...
create(object type "string" dxl (tempStringOf(DXLsrc)) attribute NameAttr)
delete(DXLsrc)


2 There is also this little string technique for writing paragraphs. Note that there is only one set of double-quotes, first and last, the others inside the text are escaped. The natural End-Of-Lines in the editor are interpreted as part of the string:

 

 

string NameAttr = "Whatever"
string DxlCode  =
"string Text = obj.\"Object Text\"
if (null Text)//
then obj.attrDXLName = \"Text is null\"
else obj.attrDXLName = \"There is Text\"
"    // end definition of string DxlCode
 
create(object type "string" dxl DxlCode attribute NameAttr)
print "DxlCode [" DxlCode "]\n"


I find that string paragraph method easier to read than the Buffer append method.
When the DxlCode uses variables, such as passing into it the name of the Attr to check, the extra string concatenation will matter if you build the DxlCode frequently; in which case you could combine both methods:
{code}
string NameAttr = "Rational"
DXLsrc = "string Text = obj."
DxlSrc += NameAttr
DXLsrc += "
if (null Text)//
then obj.attrDXLName = \"Text is null\"
else obj.attrDXLName = \"There is Text\"
"

Which, now that I look at it, isn't very easy to read!

 

 

 

  • Louie

 

 

Many many thanks for both tips.
I will consider them in the next task.

Thanks for your help.
Knut

Re: Create a DXL Attribute
SystemAdmin - Thu Dec 01 14:33:47 EST 2011

llandale - Fri Sep 02 12:03:22 EDT 2011

Nothing wrong with that, but perhaps these two little technques have some merit:
You wrote this:

string NameAttr = "Whatever"
Buffer DXLsrc = create
DXLsrc  =  "string Text = obj.\"Object Text\""
DXLsrc +=  "if (null Text)//"
DXLsrc +=  "then obj.attrDXLName = \"Text is null\""
DXLsrc +=  "else obj.attrDXLName = \"There is Text\""
 
string DxlCode = stringOf DXLsrc
delete DXLsrc
print "DxlCode [" DxlCode "]\n"
create(object type "string" dxl DxlCode attribute NameAttr)


1 The following may prevent some leakage in memory. The results of tempStringOf(Buffer) must be disposed of immediately such as printing, writing to a file, display in a dialog, assigning to an attr value, or in this case giving to the attr def. If you assign it to a string variable you can (in fact will) get future corruption as the space of the buffer can and will get overwritten, changing the value of the variable. This won't matter in this little code but does matter in your much larger scripts, say retrieving the value of 10,000 Object Text values.

So use tempStringOf(Buffer) when you are finally disposing its contents.

 

...
create(object type "string" dxl (tempStringOf(DXLsrc)) attribute NameAttr)
delete(DXLsrc)


2 There is also this little string technique for writing paragraphs. Note that there is only one set of double-quotes, first and last, the others inside the text are escaped. The natural End-Of-Lines in the editor are interpreted as part of the string:

 

 

string NameAttr = "Whatever"
string DxlCode  =
"string Text = obj.\"Object Text\"
if (null Text)//
then obj.attrDXLName = \"Text is null\"
else obj.attrDXLName = \"There is Text\"
"    // end definition of string DxlCode
 
create(object type "string" dxl DxlCode attribute NameAttr)
print "DxlCode [" DxlCode "]\n"


I find that string paragraph method easier to read than the Buffer append method.
When the DxlCode uses variables, such as passing into it the name of the Attr to check, the extra string concatenation will matter if you build the DxlCode frequently; in which case you could combine both methods:
{code}
string NameAttr = "Rational"
DXLsrc = "string Text = obj."
DxlSrc += NameAttr
DXLsrc += "
if (null Text)//
then obj.attrDXLName = \"Text is null\"
else obj.attrDXLName = \"There is Text\"
"

Which, now that I look at it, isn't very easy to read!

 

 

 

  • Louie

 

 

I have a script to create a DXL attribute that I generate by Edit-> Attributes-> New-> DXL Attribute, enter the script after browsing and selecting new, ta da, new attribute

I would like to create the DXL attribute by way of a DXL Menu. I have a recognized menu and added the necesary *.idx and *.hlp files. My question is, is it possible to add a create line within the same dxl attribute script file, or would it be better to create the dxl attribute in a separate script file and call the script that creates the attribute?

I would just like to avoid having to add the code and create the new attribute in each module I plan to use it and prefer to just go to the menu and select from the pulldown and have the dxl attribute generated.

Thanks in advance!

Re: Create a DXL Attribute
llandale - Thu Dec 01 16:22:48 EST 2011

SystemAdmin - Thu Dec 01 14:33:47 EST 2011
I have a script to create a DXL attribute that I generate by Edit-> Attributes-> New-> DXL Attribute, enter the script after browsing and selecting new, ta da, new attribute

I would like to create the DXL attribute by way of a DXL Menu. I have a recognized menu and added the necesary *.idx and *.hlp files. My question is, is it possible to add a create line within the same dxl attribute script file, or would it be better to create the dxl attribute in a separate script file and call the script that creates the attribute?

I would just like to avoid having to add the code and create the new attribute in each module I plan to use it and prefer to just go to the menu and select from the pulldown and have the dxl attribute generated.

Thanks in advance!

Well I've written a lot of self-deploying Triggers and this is basically the same thing. You need to get a string variable that contains the code to deploy. I see 3 options:
  • hard code it:
string DxlCode = "obj.attrDXLName = \"Last Modified: \" obj.\"Last Modified On\""
This gets hard to read as you have to escape with a slash all the double quotes and all the slashes. I could not keep up with those that were 50 lines long, but suspect many other folks can handle it.
  • Hard code reading it:
string DxlCode = readFile("\\\\MyCommonServer\MyAddins\MyAttrDXL\MyName.dxl")
This is actually realistic since you have already deployed your addins in some hard coded spot on the network.
  • Invoke a dialog that uses a "fileName" DBE to let the user browse for it.
I found this to be unrealistic even for me to do it and a complete waste of time to have normal folks do it. This would work if you knew to default the location to the server above and set your fileName to default to that, but if you do that you could just hard code it.

The Deploy part is pretty straight forward:
  • current = mod
  • AttrDef ad = create(object dxl DxlCode type "String" attribute "dxl_LastModified")

Debug mode would certainly print DxlCode.

I've been tempted to write a simple program that accepts a string and escapes the quotes and the slashes. Then I'd get the code to work in an attribute, copy and past into the program, then copy and paste the results into the "string DxlCode" statement above.

-Louie

"Normal folks" means "Standard Users"!

Re: Create a DXL Attribute
SystemAdmin - Thu Dec 01 17:28:37 EST 2011

llandale - Thu Dec 01 16:22:48 EST 2011
Well I've written a lot of self-deploying Triggers and this is basically the same thing. You need to get a string variable that contains the code to deploy. I see 3 options:

  • hard code it:
string DxlCode = "obj.attrDXLName = \"Last Modified: \" obj.\"Last Modified On\""
This gets hard to read as you have to escape with a slash all the double quotes and all the slashes. I could not keep up with those that were 50 lines long, but suspect many other folks can handle it.
  • Hard code reading it:
string DxlCode = readFile("\\\\MyCommonServer\MyAddins\MyAttrDXL\MyName.dxl")
This is actually realistic since you have already deployed your addins in some hard coded spot on the network.
  • Invoke a dialog that uses a "fileName" DBE to let the user browse for it.
I found this to be unrealistic even for me to do it and a complete waste of time to have normal folks do it. This would work if you knew to default the location to the server above and set your fileName to default to that, but if you do that you could just hard code it.

The Deploy part is pretty straight forward:
  • current = mod
  • AttrDef ad = create(object dxl DxlCode type "String" attribute "dxl_LastModified")

Debug mode would certainly print DxlCode.

I've been tempted to write a simple program that accepts a string and escapes the quotes and the slashes. Then I'd get the code to work in an attribute, copy and past into the program, then copy and paste the results into the "string DxlCode" statement above.

-Louie

"Normal folks" means "Standard Users"!

I received the error

badly formed token ("C:\Program)

for this line:

string DxlCode = readfile("C:\Program Files\IBM\Rational\DOORS\9.3\lib\dxl\addins\MyDXL\myDXLattribute.dxl")

I copied the pathname directly from my explorer window and added the file at the end, so I wouldn't miss a folder or \ ..... is there an issue because it is in the same folder as the dxl menu? I wanted to keep everything together to make life easier.

Re: Create a DXL Attribute
kbmurphy - Thu Dec 01 20:09:51 EST 2011

SystemAdmin - Thu Dec 01 17:28:37 EST 2011
I received the error

badly formed token ("C:\Program)

for this line:

string DxlCode = readfile("C:\Program Files\IBM\Rational\DOORS\9.3\lib\dxl\addins\MyDXL\myDXLattribute.dxl")

I copied the pathname directly from my explorer window and added the file at the end, so I wouldn't miss a folder or \ ..... is there an issue because it is in the same folder as the dxl menu? I wanted to keep everything together to make life easier.

Change your \ to / or change your \ to \\

Re: Create a DXL Attribute
SystemAdmin - Fri Dec 02 11:24:01 EST 2011

kbmurphy - Thu Dec 01 20:09:51 EST 2011
Change your \ to / or change your \ to \\

Thanks! That fixed it. Now my last question is how do I display the column in the current view? I see the dxl attribute is created but it is not being displayed in the current window.

I added the line

obj.attrDXLName = Results

and declared Results as a string but I recieve errors:

null Object parameter was passed into argument position 1
null string parameter was passed into argument position 2

When I take them out again, the code works, but the column isnt displayed in the current view

Re: Create a DXL Attribute
llandale - Fri Dec 02 12:25:33 EST 2011

SystemAdmin - Fri Dec 02 11:24:01 EST 2011
Thanks! That fixed it. Now my last question is how do I display the column in the current view? I see the dxl attribute is created but it is not being displayed in the current window.

I added the line

obj.attrDXLName = Results

and declared Results as a string but I recieve errors:

null Object parameter was passed into argument position 1
null string parameter was passed into argument position 2

When I take them out again, the code works, but the column isnt displayed in the current view

I think you are confusing these two parts:
  • The Attr-DXL part looks like something this:
    • string Results = calculation, usually simple but sometimes very complex.
    • obj.attrDXLName = Results
  • The Deployment Part looks something like this:
    • string DxlCode = get the Attr-DXL part somehow
    • create(object dxl DxlCode type "String" attribute "NameOfAttrDXL")
    • // note that "obj" and "attrDXLName" are declared but have no value in the Deployment Part; and should not be used there.

The Deployment Part code is run on-demand from the open module, and creates the attribute. You would then use the normal GUI to add ..err.. insert a new column with that attribute to the current view, then save the view.

  • Louie

Re: Create a DXL Attribute
SystemAdmin - Mon Dec 05 12:30:31 EST 2011

llandale - Fri Dec 02 12:25:33 EST 2011
I think you are confusing these two parts:

  • The Attr-DXL part looks like something this:
    • string Results = calculation, usually simple but sometimes very complex.
    • obj.attrDXLName = Results
  • The Deployment Part looks something like this:
    • string DxlCode = get the Attr-DXL part somehow
    • create(object dxl DxlCode type "String" attribute "NameOfAttrDXL")
    • // note that "obj" and "attrDXLName" are declared but have no value in the Deployment Part; and should not be used there.

The Deployment Part code is run on-demand from the open module, and creates the attribute. You would then use the normal GUI to add ..err.. insert a new column with that attribute to the current view, then save the view.

  • Louie

Ah I see, got it. Thanks again for all you help!

Re: Create a DXL Attribute
Estebell - Thu Sep 27 03:04:27 EDT 2012

SystemAdmin - Mon Dec 05 12:30:31 EST 2011
Ah I see, got it. Thanks again for all you help!

Hi,

I tried to create a new attribute DXL following your script but an error occurs on the last line.

Here is my code :

string attName = "AS Identifiant Auto"
AttrDef attDef1 = find(m, "AS Identifiant Auto")

Buffer DXLsrc = create
DXLsrc = "if (!isDeleted(obj)){"
DXLsrc += "bool bExigence = obj.\"AS Exigence\""
DXLsrc += "if (bExigence == true) {"
DXLsrc += "int iNumero = (obj.\"Absolute Number\")"
DXLsrc += "string SPrefixeId = obj.\"AS Prefixe Id\""
DXLsrc += "obj.attrDXLName = SPrefixeId \"\" iNumero \"\"}}}"
string DxlCode = stringOf DXLsrc

if (null (attDef1)){
AttrDef ad3 = create(object dxl DxlCode type "string" attribute attName)
}

The error is : <Line:14> Valeur DXL non valide pour l'attribut 'AS Identifiant Auto' du type 'string'

What is wrong with that code?

Re: Create a DXL Attribute
Peter_Albert - Thu Sep 27 04:34:02 EDT 2012

Estebell - Thu Sep 27 03:04:27 EDT 2012
Hi,

I tried to create a new attribute DXL following your script but an error occurs on the last line.

Here is my code :

string attName = "AS Identifiant Auto"
AttrDef attDef1 = find(m, "AS Identifiant Auto")

Buffer DXLsrc = create
DXLsrc = "if (!isDeleted(obj)){"
DXLsrc += "bool bExigence = obj.\"AS Exigence\""
DXLsrc += "if (bExigence == true) {"
DXLsrc += "int iNumero = (obj.\"Absolute Number\")"
DXLsrc += "string SPrefixeId = obj.\"AS Prefixe Id\""
DXLsrc += "obj.attrDXLName = SPrefixeId \"\" iNumero \"\"}}}"
string DxlCode = stringOf DXLsrc

if (null (attDef1)){
AttrDef ad3 = create(object dxl DxlCode type "string" attribute attName)
}

The error is : <Line:14> Valeur DXL non valide pour l'attribut 'AS Identifiant Auto' du type 'string'

What is wrong with that code?

You are closing too many curly brackets in the last line of the DXL code, and you lack the new lines, or at least semicolons to distinguish commands. Try

string attName = "AS Identifiant Auto"
Buffer DXLsrc = create
DXLsrc = "if (!isDeleted(obj)){\n"
DXLsrc += "  bool bExigence = obj.\"AS Exigence\"\n"
DXLsrc += "  if (bExigence == true) {\n"
DXLsrc += "    int iNumero = (obj.\"Absolute Number\")\n"
DXLsrc += "    string SPrefixeId = obj.\"AS Prefixe Id\"\n"
DXLsrc += "    obj.attrDXLName = SPrefixeId \"\" iNumero \"\"\n"
DXLsrc += "  }\n"
DXLsrc += "}"
string DxlCode = stringOf DXLsrc
 
delete DXLsrc 
create(object type "string" dxl DxlCode attribute attName)

Re: Create a DXL Attribute
Estebell - Thu Sep 27 05:04:41 EDT 2012

Peter_Albert - Thu Sep 27 04:34:02 EDT 2012

You are closing too many curly brackets in the last line of the DXL code, and you lack the new lines, or at least semicolons to distinguish commands. Try

string attName = "AS Identifiant Auto"
Buffer DXLsrc = create
DXLsrc = "if (!isDeleted(obj)){\n"
DXLsrc += "  bool bExigence = obj.\"AS Exigence\"\n"
DXLsrc += "  if (bExigence == true) {\n"
DXLsrc += "    int iNumero = (obj.\"Absolute Number\")\n"
DXLsrc += "    string SPrefixeId = obj.\"AS Prefixe Id\"\n"
DXLsrc += "    obj.attrDXLName = SPrefixeId \"\" iNumero \"\"\n"
DXLsrc += "  }\n"
DXLsrc += "}"
string DxlCode = stringOf DXLsrc
 
delete DXLsrc 
create(object type "string" dxl DxlCode attribute attName)

Thank's a lot ! It works.

Re: Create a DXL Attribute
Mathias Mamsch - Thu Sep 27 05:58:26 EDT 2012

Peter_Albert - Thu Sep 27 04:34:02 EDT 2012

You are closing too many curly brackets in the last line of the DXL code, and you lack the new lines, or at least semicolons to distinguish commands. Try

string attName = "AS Identifiant Auto"
Buffer DXLsrc = create
DXLsrc = "if (!isDeleted(obj)){\n"
DXLsrc += "  bool bExigence = obj.\"AS Exigence\"\n"
DXLsrc += "  if (bExigence == true) {\n"
DXLsrc += "    int iNumero = (obj.\"Absolute Number\")\n"
DXLsrc += "    string SPrefixeId = obj.\"AS Prefixe Id\"\n"
DXLsrc += "    obj.attrDXLName = SPrefixeId \"\" iNumero \"\"\n"
DXLsrc += "  }\n"
DXLsrc += "}"
string DxlCode = stringOf DXLsrc
 
delete DXLsrc 
create(object type "string" dxl DxlCode attribute attName)

By the way, DXL code in a string becomes much more readable if you use multi-line strings in DXL:
 

Buffer DXLsrc = create
DXLsrc = "
if (!isDeleted(obj)) {
  bool bExigence = obj.\"AS Exigence\"
  if (bExigence == true) {
  int iNumero = (obj.\"Absolute Number\")
  string SPrefixeId = obj.\"AS Prefixe Id\"
  obj.attrDXLName = SPrefixeId \"\" iNumero \"\"
  }
}
"

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS